//
//  SEWorld.h
//  Space Explorer
//
//  Created by Yann Blaudin de Thé on 14/04/13.
//  Copyright (c) 2013 TeaTime. All rights reserved.
//

#ifndef __Space_Explorer__SEWorld__
#define __Space_Explorer__SEWorld__

#include <vector>
#include <fstream>
#include <string>

#include <irrlicht.h>
#include <btBulletDynamicsCommon.h>

#include "SEUtil.h"
#include "SEClock.h"
#include "SEMisc.h"
#include "SEPlanet.h"
#include "SEVessel.h"
#include "SECockpit.h"


class SEWorld {
private:    
    irr::IrrlichtDevice *_irr_device;
    
//    btDiscreteDynamicsWorld *_btWorld;
//    irr::core::list<btRigidBody*> _btObjects;
//    
//    btBroadphaseInterface *_BroadPhase;
//	btDefaultCollisionConfiguration *_CollisionConfiguration;
//	btCollisionDispatcher *_Dispatcher;
//	btSequentialImpulseConstraintSolver *_Solver;

    irr::video::IVideoDriver *_irr_driver;
    irr::scene::ISceneManager *_irr_smgr;
    irr::gui::IGUIEnvironment *_irr_guienv;
    irr::scene::ICameraSceneNode *_irr_cam;
    
    irr::scene::ILightSceneNode *_light;
    SEPlanet* _sun;
    
    vec3d _cam_ph_pos;
    
    SEClock _clock;
    SpiceDouble _t_wrap;
    
    std::vector<SEPlanet*> _planets;
    std::vector<SEVessel*> _vessels;
    
    int _lastFPS;
    
    SECockpit* _cockpit;
    
public:
    SEWorld(irr::IEventReceiver* _irr_receiver);
    ~SEWorld();
    
    void loadBSC(const std::string&);
    
    irr::IrrlichtDevice* getIrrDevice();
    
    irr::scene::ISceneManager* getIrrSceneManager();
    
    SEPlanet* createPlanet(SEPlanet* attractor, const irr::core::stringw& disp_name, const std::string& spice_name, const std::string& ground_tex, const std::string& cloud_tex, const std::string& normal_tex);
    
    SEVessel* createVessel(const irr::core::stringw& disp_name, const std::string& mesh_file);
    
    irr::scene::ILightSceneNode* createLight(SEPlanet* body);
    
    irr::scene::ILightSceneNode* getLight();
    
    SECockpit* getCockpit();
    
    std::vector<SEPlanet*>& getPlanets();
    
    std::vector<SEVessel*>& getVessels();
    
    btVector3 getGravite(const btVector3& position);
    
    irr::scene::ICameraSceneNode* getIrrCamera();
    
    vec3d getCameraPos() const;
    
    void setCameraPos(const vec3d& pos);
    
    SpiceDouble setWarpCoeff(SpiceDouble coeff);
    
    bool run();
    
    void loop();
    
};

#endif /* defined(__Space_Explorer__SEWorld__) */

